#!/bin/bash
## filename: while-until-for_sum.sh

# 使用当型循环求 sum(1..100)
((i=0,s=0))        # i=0 ; s=0
while ((i<100)) ; do ((i++,s+=i)) ; done
echo sum\(1..100\)=$s

# 使用直到型循环求 sum(1..100)
((i=0,s=0))
until ((i==100)) ; do ((i++,s+=i)) ; done
echo sum\(1..100\)=$s

# 使用C风格的 for 循环求 sum(1..100)
for ((s=0,i=1;i<=100;s+=i,i++)) ; do : ; done
echo sum\(1..100\)=$s

